package com.dwxt.cdms.controller;

import com.alibaba.fastjson.JSON;
import com.dwxt.cdms.base.Page;
import com.dwxt.cdms.entity.LbWatch;
import com.dwxt.cdms.entity.laibang.LbWatchVO;
import com.dwxt.cdms.service.LbWatchService;
import com.dwxt.common.base.BaseResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/cdms/lb")
@RestController
public class LbWatchController {

    @Autowired
    private LbWatchService lbWatchService;

    /**
     * 分页查询
     */
    @RequestMapping("/page")
    public BaseResult page(Page page,Integer customerId, String name ,String type,String category) {
        return lbWatchService.page(page,customerId, name ,type,category);
    }

    /**
     * 按用户分组查询最新数据并分页
     * @param page
     * @param name
     * @param type
     * @param category
     * @return
     */
    @RequestMapping("/pageGroup")
    public BaseResult pageGroup(Page page, String name ,String type,String category){
        return lbWatchService.pageGroup(page,name,type,category);
    }

    /**
     * list查询
     */
    @RequestMapping("/list")
    public BaseResult list() {
        return lbWatchService.list();
    }

    /**
     * 新增
     */
    @RequestMapping("/add")
    public BaseResult add(LbWatch lbWatch) {
        return lbWatchService.add(lbWatch);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public BaseResult delete(Integer id){
        return lbWatchService.delete(id);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public BaseResult update(LbWatch lbWatch){
        return  lbWatchService.update(lbWatch);
    }

    private LbWatch VO2Entity(LbWatchVO vo) {
        LbWatch entity = new LbWatch();
        BeanUtils.copyProperties(vo, entity);
        entity.setAddAmbientBeaconDTO(JSON.toJSONString(vo.getAddAmbientBeaconDTO()));
        entity.setAddBodyTemperatureDTO(JSON.toJSONString(vo.getAddBodyTemperatureDTO()));
        entity.setAddDevicePowerDTOList(JSON.toJSONString(vo.getAddDevicePowerDTOList()));
        entity.setAddHealthDTO(JSON.toJSONString(vo.getAddHealthDTO()));
        entity.setAddHumitureDTO(JSON.toJSONString(vo.getAddHumitureDTO()));
        entity.setAddPositionStatusDTOList(JSON.toJSONString(vo.getAddPositionStatusDTOList()));
        entity.setAddSignalQualityDTO(JSON.toJSONString(vo.getAddSignalQualityDTO()));
        entity.setAddWearStatusDTO(JSON.toJSONString(vo.getAddWearStatusDTO()));
        entity.setAddWifiDTO(JSON.toJSONString(vo.getAddWifiDTO()));
        return entity;
    }


    @RequestMapping("/selectRemindList")
    public BaseResult selectRemindList(Integer customerId){
        return  lbWatchService.selectRemindList(customerId);
    }
    @RequestMapping("/deleteRemind")
    public BaseResult deleteRemind(Integer customerId,String taskId){
        return  lbWatchService.deleteRemindByCustomerIdAndTaskId(customerId,taskId);
    }

}

